home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 52856 / 52856.xpi / chrome / content / ff-overlay.js < prev    next >
Text File  |  2009-11-29  |  2KB  |  60 lines

  1. handytab.onFirefoxLoad = function(e) {
  2.   var prefSrv = Components.classes["@mozilla.org/preferences-service;1"]
  3.                           .getService(Components.interfaces.nsIPrefService);
  4.   var prefs = prefSrv.getBranch("extensions.handytab.");
  5.  
  6.   var firstRun = prefs.getBoolPref("firstrun");
  7.   if (firstRun) {
  8.     handytab.addButtonsToToolbar();
  9.     prefs.setBoolPref("firstrun", false);
  10.     prefSrv.savePrefFile(null);
  11.   }
  12.   
  13.   document.getElementById("contentAreaContextMenu")
  14.           .addEventListener("popupshowing", function (e){ handytab.showFirefoxContextMenu(e); }, false);
  15. };
  16.  
  17. handytab.addButtonsToToolbar = function() {
  18.   try {
  19.     var toolbar = document.getElementById("nav-bar");
  20.     var curSet = toolbar.currentSet;
  21.     var newSet = curSet;
  22.     var buttons = ['show-handytab-button'];
  23.  
  24.     for (var i = 0; i < buttons.length; i++) {
  25.       if (curSet.indexOf(buttons[i]) == -1) {
  26.         // Place the button after the home-button
  27.         if (newSet.indexOf("home-button") != -1)
  28.           newSet = newSet.replace(/home-button/, "home-button," + buttons[i]);
  29.         else if (newSet.indexOf("stop-button") != -1)  // else place the button after the stop-button
  30.           newSet = newSet.replace(/stop-button/, "stop-button," + buttons[i]);
  31.         else  // else at the end
  32.           newSet += "," + buttons[i];
  33.       }
  34.     }
  35.  
  36.     if (newSet != curSet) {
  37.       toolbar.setAttribute("currentset", newSet);
  38.       toolbar.currentSet = newSet;
  39.       document.persist("nav-bar", "currentset");
  40.       // If you don't do the following call, funny things happen
  41.       try {
  42.         BrowserToolboxCustomizeDone(true);
  43.       }
  44.       catch (e) { }
  45.     }
  46.   }
  47.   catch(e) { }
  48. };  
  49.  
  50. handytab.showFirefoxContextMenu = function(e) {
  51.   if (e.originalTarget != document.getElementById("contentAreaContextMenu")) return;
  52.   if (!gContextMenu) return;
  53.  
  54.   var hideSelf = !gContextMenu.onLink && !gContextMenu.onImage;
  55.   document.getElementById("context-handytab-marklink").hidden = hideSelf;
  56.   document.getElementById("context-handytab-markpage").hidden = !hideSelf;
  57. };
  58.  
  59. window.addEventListener("load", handytab.onFirefoxLoad, false);
  60.